package com.yanqu.road.server.cmd.banquet.crossBanquet.auto;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.banquet.CrossBanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.banquet.BanquetModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.S_BANQUET_CROSS_ACTIVITY_REWARD_NOTICE, desc = "定时来拉人加人气道具")
public class BanquetAutoNoticePopCmd extends AbstractCommand {

	private CrossBanquetProto.CrossNoticeAutoBanquetPopRewardReq reqMsg;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		reqMsg = CrossBanquetProto.CrossNoticeAutoBanquetPopRewardReq.parseFrom(packet.getBytes());
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		List<Long> outLineUserIdList = new ArrayList<>();
		for(long userId : reqMsg.getUserIdsList()){
			GamePlayer gamePlayer = GamePlayerMgr.getOnlinePlayer(userId);
			if(gamePlayer != null){
				gamePlayer.getModule(BanquetModule.class).sendGetAutoPopReward();
			}else{
				outLineUserIdList.add(userId);
			}
		}
		for(long outLineUserId : outLineUserIdList){
			GamePlayer player1 = GamePlayerMgr.getPlayer(outLineUserId);
			if(player1 != null){
				player1.getModule(BanquetModule.class).sendGetAutoPopReward();
			}
		}
	}

	@Override
	public void sendData(GamePlayer player) {

	}
}
